<template>
  <el-aside :width="isCollapse ? '64px' : '200px'">
    <el-menu
      background-color="#545c64"
      text-color="#fff"
      active-text-color="#409eff"
      :unique-opened="true"
      :collapse="isCollapse"
      :collapse-transition="false"
      :router="true"
      :default-active="activePath"
      
    >
      <div class="toggle-button" @click="toggleCollapse">|||</div>
      <el-submenu :index="item.id + ''" v-for="item in menuList" :id="item.id">
        <template slot="title">
          <i :class="itemObj[item.id]"></i>
          <span>{{ item.authName }}</span>
        </template>
        <el-menu-item
          :index="subItem.path"
          v-for="subItem in item.children"
          style="padding-left: 80px"
          @click="saveNavState(subItem.path)"
        >
          <template slot="title">
            <i class="el-icon-menu"></i>
            <span>{{ subItem.authName }}</span>
          </template>
        </el-menu-item>
      </el-submenu>
    </el-menu>
  </el-aside>
</template>

<script>
export default {
  name: 'AsideList',
  props: {
    menuList: {
      type: Array,
      default() {
        return []
      },
    },
  },
  data() {
    return {
      itemObj: {
        125: 'iconfont icon-users',
        103: 'iconfont icon-tijikongjian',
        101: 'iconfont icon-shangpin',
        102: 'iconfont icon-danju',
        145: 'iconfont icon-baobiao',
      },
      isCollapse: false,
      activePath: '',
    }
  },
  created() {
    this.activePath = window.sessionStorage.getItem('activePath')
  },
  methods: {
    handleOpen(key, keyPath) {
      console.log(key, keyPath)
    },
    handleClose(key, keyPath) {
      console.log(key, keyPath)
    },
    toggleCollapse() {
      this.isCollapse = !this.isCollapse
    },
    saveNavState(activePath) {
      window.sessionStorage.setItem('activePath', activePath)
      this.activePath = activePath
    },
  },
}
</script>

<style scoped>
.iconfont {
  margin-right: 10px;
}
.el-menu {
  border-right: 0;
}
.toggle-button {
  background-color: #434a50;
  font-size: 10px;
  line-height: 24px;
  color: #fff;
  letter-spacing: 0.3em;
  cursor: pointer;
}
.el-aside {
  background-color: #545c64;
  color: #333;
  text-align: center;
}
</style>
